import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:crypto/crypto.dart' as sign;

class SHASignInterceptor extends InterceptorsWrapper {
  @override
  Future onRequest(RequestOptions options) async {
//    var pk=await PackageInfo.fromPlatform();
//    var vn = pk.version;//"2.1.1";//await mmkv.getString(MmkvFlutter.VERSION);
//    var time = DateTime.now().millisecondsSinceEpoch ~/ 1000;
//    var device = "device";//await mmkv.getString("DEVICE");
//    var signKey = BuildConfig.SHA256_KEY;
//    var signContent = "$signKey&${options.path.toLowerCase().substring(1)}&$time&$vn";
//    var head = {
//      "TIME": time,
//      "VERSION": vn,
//      "device": device,
//      "TOKEN": await TokenData.token,
//      "SIGN": sha256(signContent)
//    };
//    options.headers.addAll(head);
    return options;
  }

  String sha256(String body) {
    var bytes = utf8.encode(body);
    return sign.sha256.convert(bytes).toString();
  }
}
